home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
176-200
/
scopedisk180
/
arexxtutorial
/
listenv
/
listenv.tutor
< prev
next >
Wrap
Text File
|
1995-03-19
|
7KB
|
243 lines
/* ListEnv.rexx */
/* List Amiga "ENV:" file style environment variables.
*
* Note: For programming, I like tabs set at 4, not 8, so this may
* look funny at 8!
*/
/* Written by Don Meyer (Stormgate Software).
* BIX: donmeyer
* GEnie: D.MEYER
* Plink: STORMGATE
*
* This program released into the Public Domain.
*/
/* Modifications by Jeremy Farrance (ETC Software).
* Extensive documentation too!
* Plink: JEREMY
*
* This program remains in the Public Domain.
*
* Bananas
*/
/* Ver. Date Who Notes
* ---- --------- --- -----------------------------
* 0.0 12-Feb-89 DTM Creation
* 0.1 19-Mar-89 DTM Accept a command line env var name.
*
* 0.2 17-Apr-89 JRF General improvements, fixed ENV names
* with ' ' spaces, added '?' Usage:,
* added opensupport(), now checks if
* ENV: assignment exists and added
* a files listed count, others...
*/
/* Let ARexx know we want user CTRL-C's trapped... see BREAK_C: below */
signal on BREAK_C
/* Opens rexxsupport.library if its not (~) already open */
if ~show('L',"rexxsupport.library") then do
if addlib('rexxsupport.library',0,-30,0) then
say 'added rexxsupport.library'
else do;
say 'support library not available'
exit 10
end
end
/* Uses the 'Assign' option of showlist() to verify that ENV: is there */
/* See the 1.06 update.doc for more info */
if ~showlist('A','ENV') then do
say 'ENV: not assigned.'
exit 10
end
/* Get the (if any) command line arguments */
arg filename
/* if the command line argument was a '?' then we display usage */
if filename == "?" then do
say 'Usage: ListEnv [Environment variable name]'
exit 0
end
/* I added this in at the last minute. See if you can figure out what */
/* it does, if not leave me EMail on PLink and I'll explain it. :-) */
if length(filename) = 1 & datatype(filename,'U') then pattern = filename
/* If the command line argument was not "" then we take the argument as */
/* a single file name a perform similar to the AmigaDOG 'getenv' command */
if filename ~= "" & pattern = 'PATTERN' then do
call got_one(filename)
exit 0
end
/* If we get to here, the user did not specify a file name on the
* command line, so show the contents of all environment variables. */
/* Get a list of the files in the ENV: directory using ":" as separator */
/* See the 1.06 update.doc for this enhancement to showdir() */
files = showdir( "ENV:", "File", ":" )
/* initialize count to '0' otherwise when we use it below in the
* expression 'count = count + ...' we get an error because 'count's
* uninitialized is 'count = "COUNT"' just like all ARexx variable
* the error being that "COUNT" is not a number and cant be added (+)
* to anything. Try commenting out this line to see what happens */
count = 0
/* Main 'do' loop - extracts filenames as separated by ':'.
* See the ARexx manual page(s) 79-80 for more info on the technique
* used below to 'parse' the result of the above showdir() command */
do forever
parse upper var files name ':' files
/* This breaks us out of the main 'do' loop when all the names have
* been 'parse'd out of files */
if name == '' then leave
/* Ignore any icon files which may be present, by using the 'iterate'
* command we effectively transfer control to the 'end' statement below */
if right(name, 5) == ".INFO" then iterate
/* This is the rest of the last minute addition that you should be
* figuring out... */
if pattern ~= 'PATTERN' & left(name,1) ~= pattern then iterate
/* By combining the actual function call with the loops counter we can
* act a little bit like 'C' here... */
count = count + got_one(name) /* This takes us to the funtion below */
end /* This is the 'end' of the Main Loop AND where the 'iterate's
* sort of 'end'-up. */
/* Now just see how many files we displayed for the user */
/* If we didn't display any, then we 'say' so */
if count > 0 then say count' files'
else say 'No environment variables found'
/* And this statement tells ARexx we are done here and can exit the program */
exit 0
/*------------------------------------------------------------------*/
/* Handle opening a file and printing out it's (partial) contents. */
got_one: procedure
/* get the argument that was sent to this function in the variable 'name' */
arg name
/* If we cant open (find) the requested file, we tell the user about it
* and return '0' so that the 'count'er above does not get incremented */
if ~open( src, "ENV:" || name, "Read" ) then do
say "** Unable to access 'ENV:" || name || "' **"
return(0)
end
/* 'src' is like an AmigaDOS file handle now, and we can use it to read */
value = readln( src )
/* We use 'equals' for 2 reasons, 1) because it will be fully evaluated
* and assigned a value below and 2) this way we don't have ARexx using
* up memory on variables that are a waste */
equals = readch( src, 1 ) /* Get the LF, if there is one throw it away */
/* if we haven't reached the end of the file, then we append a visual
* marker at the end of the value so the user knows there was more than
* one line in the environment variable */
if ~eof( src ) then value = value || '1B'x || "[33m ...<more>" || '1B'x || "[31m"
/* if length of 'value' is less than 50 then everything will look nice */
if length(value) < 50 then equals = " = "
/* if not we need to adjust what will be displayed. We do this by adding
* a LineFeed ('0A'x) to the '=' sign. This will force the 'value' to
* print on a new line below. */
else do
equals = '1B'x || "[32m =" || '1B'x || "[31m" || '0A'x || " "
/* AND if the length of the 'value' is still too long for the display
* then we chop it and add '...' to the end to let the user know */
if length(value) > 69 then
value = space(left(value,69),0) || '1B'x || "[32m..." || '1B'x || "[31m"
end /* 'end' for the above 'else do' */
/* Now we report our findings to the user... */
say left(name,20) || equals || '"' || value || '"'
/* Clean up by closing the file we opened */
call close(src)
/* And 'return' a '1' to the calling function because its keeping 'count' */
return(1)
/*-----------------------------------------------------------------------*
* User pressed control-C.
* We set this up by the 'signal on BREAK_C' at the start of the program */
break_c:
say "*** Control-C recieved. Stopped by user. ***"
exit 5
/*------------------------------------------------------------------*/